const https = require('https');
//导入 fs 模块
const fs = require('fs');
const url = 'https://www.tianqiapi.com/api/?version=v1&city=%E5%8C%97%E4%BA%AC&appid=23941491&appsecret=TXoD5e8P';

https.get(url, (response) => {
  let data = '';

  response.on('data', (chunk) => {
    data += chunk;
  });

  response.on('end', () => {
    // 在这里处理响应的数据
    data = JSON.parse(data);
    fs.writeFileSync('./天气.json', JSON.stringify(data, null, 2));
  });

}).on('error', (error) => {
  console.error(`请求发生错误: ${error.message}`);
});